package com.jams.goodox.adapter;

import android.graphics.Paint;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jams.goodox.R;
import com.jams.goodox.TownApplicationLike;
import com.jams.goodox.entity.PointProduct;
import com.jams.library.fresco.FrescoUtil;

import java.util.Date;
import java.util.List;

/**
 * Created by Jin on 2016/5/18.
 * Description 积分产品列表适配器
 */
public class PointProductRecordAdapter extends BaseQuickAdapter<PointProduct.DataBean.ResultListBean> {

	public PointProductRecordAdapter(List<PointProduct.DataBean.ResultListBean> list) {
		super(R.layout.mine_points_product_listview, list);
	}

	@Override
	protected void convert(BaseViewHolder baseViewHolder, PointProduct.DataBean.ResultListBean resultListBean) {
		try {
			long time = new Date().getTime() / 1000;
			//b  在结束前，并且剩余数量大于0，开始时间小于当前时间
			boolean b = resultListBean.getAvailableTo() > time && resultListBean.getRemainingNumber() > 0 && resultListBean.getAvailableFrom() < time;
			baseViewHolder.setText(R.id.product_name, resultListBean.getName())
					.setText(R.id.product_point, resultListBean.getRequiredScore() + " 积分")
					.setText(R.id.product_price, "￥" + resultListBean.getUnit())
					.setTextColor(R.id.product_btn, ContextCompat.getColor(TownApplicationLike.getInstance(),R.color.font_white))
					.setBackgroundRes(R.id.product_btn, b ? R.drawable.bg_redius_theme : R.drawable.points_red_grey)
					.setText(R.id.product_tips, resultListBean.getTips());
			((TextView)baseViewHolder.getView(R.id.product_price)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
			FrescoUtil.loadNetUrl(((SimpleDraweeView) baseViewHolder.getView(R.id.product_img)), resultListBean.getPicUrl());

			if (resultListBean.getAvailableFrom() > time) {
				baseViewHolder.setText(R.id.product_btn, "敬请期待");
			} else if (resultListBean.getAvailableTo() < time || resultListBean.getRemainingNumber() == 0) {
				baseViewHolder.setText(R.id.product_btn, "兑换结束");
			} else {
				baseViewHolder.setText(R.id.product_btn, "查看详情");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
